home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 June / PCWorld_2007-06_cd.bin / temacd / wikipad / WikidPad-1.9beta2.exe / {app} / WikidPadHelp / data / InlinePythonEval.wiki < prev    next >
Encoding:
Text File  |  2006-02-24  |  3.0 KB  |  95 lines

  1. ∩╗┐++ Inline Python Eval
  2.  
  3.  
  4. +++ Security concerns
  5. WikidPad allows to evaluate and execute arbitrary Python scripts.
  6. Because this is a potential security risk, script execution is
  7. disabled by default.
  8.  
  9. To enable it, open the "Options" dialog, chapter "Other", item
  10. "Script security". In the drop-down field you can enter the level
  11. of security you want:
  12.  
  13.     * No scripts: Script execution is completely disabled. This is
  14.       the default.
  15.     * No import_scripts: Scripts on the currently open page can be
  16.       executed and expressions evaluated. Importing scripts from
  17.       other pages with the import_scripts property doesn't work (see
  18.       below how to do this).
  19.     * No global.import_scripts: Property "import_scripts" works,
  20.       but "global.import_scripts" does not
  21.     * Allow everything
  22.  
  23.  
  24. The following examples work therefore only with an appropriately relaxed security setting.
  25.  
  26.  
  27. +++ Evaluating expressions
  28. You can evaluate Python expressions directly in the editor by
  29. highlighting the expression and pressing CTRL-E. Example:
  30.  
  31. Highlight the calculation below, and type CTRL-E.
  32.  
  33. 1+2+3
  34.  
  35.  
  36. +++ Executing scripts on the same page
  37. You can also execute blocks of code within a document.  Blocks of code
  38. are defined within <% %> blocks. For example:
  39.  
  40. <%
  41. editor.GotoPos(editor.GetLength())
  42. editor.AddText('\nhello ')
  43. %>
  44.  
  45. To execute the code above, type Ctrl-E. Ctrl-E actually will execute all
  46. of the scripts on a page, including script imports.
  47.  
  48. You can assign up to 6 functions on a page to a Ctrl-# key. For example:
  49.  
  50. function 1: <% 1: editor.AddText(lib.now()) %>
  51. function 2: <% 2: lib.addDate(editor) %>
  52.  
  53. Type Ctrl-1 to execute function 1. Enter Ctrl-2 to execute function 2.
  54. This will execute at most one script. If a script with this number is
  55. found on the page, it is executed, if not, the local script imports
  56. with import_scripts are searched. If no appropriate script is found
  57. there either, the page mentioned in global.import_scripts is searched.
  58. As already said, this happens only with the right security settings.
  59.  
  60. You can define your own functions for evaluation by copying
  61. evalLibrary.py into a directory in the wikidPad install directory
  62. called "user_extensions". This file will not be touched when upgrading
  63. wikidPad.
  64.  
  65. file:///C|/Program%20Files/WikidPad/extensions/EvalLibrary.py
  66. file:///C|/Program%20Files/WikidPad/user_extensions/EvalLibrary.py
  67.  
  68.  
  69. +++ Script Imports
  70.  
  71. You can import scripts from another page using the following attribute.
  72.  
  73. [import_scripts: GlobalScriptLibrary]
  74.  
  75. Type "Ctrl-4" to see the output from script 4 on the page
  76. GlobalScriptLibrary.
  77.  
  78. You can also use \[global.import_scripts: ...] property to define a single page which will be seen as if it was imported by every page of the wiki.
  79.  
  80.  
  81. +++ Editor Control Functions
  82.  
  83. See http://www.yellowbrain.com/stc/index.html for a list of the functions
  84. available to the "editor" control.
  85.  
  86.  
  87. +++ Another Example
  88.  
  89. Highlight the line below and press CTRL-3
  90.  
  91. c:\this path\will be encoded.txt
  92.  
  93. <% 3: lib.encodeSelection(editor) %>
  94.  
  95.